export function loadMap(key) {
  window._AMapSecurityConfig = {
    securityJsCode: "0f8a7b683c7a2e528842bc3509ce12c5",
  };
  return new Promise(function (resolve, reject) {
      window.init = function () {
        console.log('script1-------onload');
        resolve(AMap)
      };
      let script = document.createElement("script");
      script.type = "text/javascript";
      script.src = "//webapi.amap.com/maps?v=1.4.15" +
        "&plugin=AMap.MarkerClusterer,AMap.RangingTool," +
        "AMap.PlaceSearch,AMap.DistrictSearch,AMap.OverlayGroup" +
        "&key=" + key + "&callback=init";
      script.onerror = reject;
      document.head.appendChild(script);
  });
};

export function loadMapUI() {
  return new Promise(function (resolve, reject) {
      let script2 = document.createElement("script");
      script2.type = "text/javascript";
      script2.src = "//webapi.amap.com/ui/1.0/main.js?v=1.0.11";
      script2.onerror = reject;
      script2.onload = function (su) {
        console.log('script2-------onload', su);
        resolve(AMapUI)
      };
      document.head.appendChild(script2);
  });
};

